const express = require( 'express' );
const router = express.Router();

let logger = require( "../../../../utils/utils.logger" );
const tools = require( "../../../../utils/utils.tools" );
const db = require( "../../../../models" );

const sequelize = db.sequelize;
const {
    Op
} = require( "sequelize" );
const speciality = require( "../../../../controllers/speciality.controller" );
/**
 * 获取个人专业所有数据
 * @route GET /api/public/personal/speciality/list
 * @group 获取个人专业 - list
 * @returns {object} 200 - 请求返回正确
 * @returns {object} 500 - 请求返回错误
 * @returns {Error}  default - Unexpected error
 */

router.get( "/list", function ( req, res ) {
    const pm = {
        limit: 1000,
        offset: 1,
        params: {
            type: 2,
            show: 1
        },
        sort: {
            prop: "skilled",
            order: "asc"
        }
    };


    let clientIp = req.headers[ 'x-forwarded-for' ] ||
        req.connection.remoteAddress ||
        req.socket.remoteAddress ||
        req.connection.socket.remoteAddress;
    logger.info( `【IP】${clientIp}【获取专业数据】 ` )
    speciality.getAllList( pm, ( data, err ) => {
        if ( err ) return res.sendResultAto( null, 401, err )

        let arr = data.data.data
        let resArr = []
        for ( let i = 0; i < arr.length; i++ ) {

            arr[ i ].createdAt = tools.timestampToTime( arr[ i ].createdAt, 'YMDHM' )
            arr[ i ].updatedAt = tools.timestampToTime( arr[ i ].updatedAt, 'YMDHM' )
            resArr.push( {
                skilled: arr[ i ].skilled*100 ,
                name: arr[ i ].name
            } )
        }
        res.sendResultAto( resArr, 200, '获取数据成功' )
    } )


} );
module.exports = router;
